home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Oct 89 / Z0021-Re WindowMenu Recip-Oct89 < prev    next >
Encoding:
Text File  |  1989-10-06  |  4.1 KB  |  166 lines  |  [TEXT/GEOL]

  1. Item    5489464                         5-Oct-89        19:13
  2.  
  3. From:   V0230                           Trace, Laurence Kirsh,VAR
  4.  
  5. To:     D2652                           Strategic Planning Sys, D Bell,PRT
  6.  
  7. cc:     MACAPP.TECH$                    MACAPP Tech
  8.  
  9. Sub:    RE WindowMenu Recipe
  10.  
  11. Don,
  12.  
  13. Here, for what it's worth, is my recipe for a Windows menu. Note: this comes
  14. from a MacApp 1.1.1 application, so some adjustment may be needed for 2.0ß9.
  15.  
  16. ======> .r file, add a cmnu declaration [5 is the ID I used in this case]
  17. resource 'cmnu' (5) {
  18.    5,
  19.    textMenuProc,
  20.    allEnabled,
  21.    enabled,
  22.    "Windows",
  23.    {
  24.    }
  25. };
  26.  
  27. ======> "global" declarations:
  28. Const
  29.     kWindowMenuID = 5; {window menu resource ID}
  30.  
  31. {$S ARes}
  32. Procedure AddToWindowMenu (AtTop: Boolean; Name: Str255);
  33. {add the name (usually a window name) to the Window menu.
  34.  If AtTop is True, the name is inserted at the top of the
  35.  menu, otherwise at the bottom.}
  36.  
  37. Var
  38.     Menu: MenuHandle;
  39.     Item: Integer;
  40.  
  41. Begin
  42.    Menu := GetMHandle (kWindowMenuID);
  43.    If AtTop
  44.    Then Item := 0  {insert before first}
  45.    Else Item := CountMItems(Menu)+1;   {insert at bottom}
  46.    InsMenuItem (Menu, 'A', Item);  {just add a dummy, because this tries to do
  47. meta-characters,}
  48.    If Item = 0 Then Item := 1;
  49.    SetItem (Menu, Item, Name)  {and this one does not}
  50. End;   {AddToWindowMenu}
  51.  
  52. {$S ARes}
  53. Procedure DeleteFromWindowMenu (Name: Str255);
  54. {remove the menu item with name Name from the Window menu.
  55.  If it's not there, do nothing}
  56.  
  57. Var
  58.     Menu: MenuHandle;
  59.     Last: Integer;
  60.     Item: Integer;
  61.     ItemName: Str255;
  62.  
  63. Begin
  64.    Menu := GetMHandle (kWindowMenuID);
  65.    Last := CountMItems (Menu);
  66.  
  67.    Item := 1;
  68.    While Item <= Last Do Begin
  69.    GetItem (Menu, Item, ItemName);
  70.    If ItemName = Name Then Begin
  71.    DelMenuItem (Menu, Item);
  72.    Item := Last {exit loop}
  73.    End;
  74.    Item := Succ(Item)
  75.    End
  76. End;   {DeleteFromWindowMenu}
  77.  
  78.  
  79. ======> in your window objects, override Open and Close:
  80. {$S AOpen}
  81. Procedure TAnyWindowObject.Open; OVERRIDE;
  82. Begin
  83.    If Not fInOpenWindow Then
  84.    AddToWindowMenu (True, WindowPeek(fWmgrWindow)^.TitleHandle^^);
  85.    INHERITED Open
  86. End;   {TAnyWindowObject.Open}
  87.  
  88. {$S AClose}
  89. Procedure TAnyWindowObject.Close; OVERRIDE;
  90. Begin
  91.    DeleteFromWindowMenu (WindowPeek(fWMgrWindow)^.TitleHandle^^);
  92.    INHERITED Close
  93. End;   {TAnyWindowObject.Close}
  94.  
  95.  
  96. ======> in your application, override DoSetUpMenus and DoMenuCommand:
  97. {$S ARes}
  98. Procedure TYourApplication.DoSetUpMenus; OVERRIDE;
  99.  
  100. Var
  101.     I: Integer;{to enable Window menu items}
  102.     Menu: MenuHandle;
  103.  
  104. Begin
  105.    INHERITED DoSetUpMenus;
  106.  
  107.    <<<< other enables >>>>
  108.  
  109.    {enable the window names in the windows menu}
  110.    Menu := GetMHandle (kWindowMenuID);
  111.    If Menu <> Nil Then
  112.    For I := 1 to CountMItems (Menu) Do
  113.    EnableItem (Menu, I);
  114. End;   {TYourApplication.DoSetUpMenus}
  115.  
  116. {$S ASelCommand}
  117. Function TYourApplication.DoMenuCommand (aCmdNumber: CmdNumber): TCommand;
  118. OVERRIDE;
  119. {Capture all CmdNumbers for use with Help window.
  120.  Open Help window if they ask for it, otherwise call INHERITED.}
  121.  
  122. Var
  123.     Menu: Integer; {menu belonging to aCmdNumber}
  124.     Item: Integer; {item belonging to aCmdNumber}
  125.     ItemName: Str255;  {name of Item}
  126.     Wind: WindowPtr;   {used to search window list for ItemName}
  127.     aName: Str255; {name of Wind}
  128.  
  129. Begin
  130.    DoMenuCommand := gNoChanges;
  131.  
  132.    {First check to see if the user selected a window name from the
  133.     Windows menu, because the handling of this is non-standard.}
  134.  
  135.    CmdToMenuItem (aCmdNumber, Menu, Item);
  136.  
  137.    If Menu = kWindowMenuID
  138.    Then Begin
  139.    GetItem (GetMHandle(Menu), Item, ItemName);
  140.  
  141.    {look through the window list}
  142.    Wind := FrontWindow;
  143.    While Wind <> Nil Do Begin
  144.    GetWTitle (Wind, aName);
  145.    If aName <> ItemName
  146.    Then Wind := WindowPtr(WindowPeek(Wind)^.NextWindow)
  147.    Else Begin
  148.    SelectWindow (Wind);
  149.    Wind := Nil {exit loop}
  150.    End
  151.    End
  152.  
  153.    End {window menu selection}
  154.  
  155.    Else If <<<< check for other command numbers...... >>>>
  156.  
  157.    Else DoMenuCommand := INHERITED DoMenuCommand (aCmdNumber)
  158.  
  159. End;   {TYourApplication.DoMenuCommand}
  160.  
  161. ======
  162. I'd appreciate any changes/improvements that anyone has to suggest.
  163.  
  164. John MacVeigh, Trace Inc.
  165.  
  166.